package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/1/16 10:02
 * @description
 */
public class Code897 {
    private List<Integer> list = new ArrayList<>();

    public TreeNode increasingBST(TreeNode root) {
        setList(root);
        TreeNode r = new TreeNode(list.get(0));
        getNode(r, 1);
        return r;
    }

    private void setList(TreeNode node) {
        if (node != null) {
            setList(node.left);
            list.add(node.val);
            setList(node.right);
        }
    }

    private TreeNode getNode(TreeNode node, int index) {
        if (index < list.size()) {
            node.right = new TreeNode(list.get(index));
            getNode(node.right, index += 1);
        }
        return node;
    }
}
